<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<jsp:include page="../common/adminContentHead.jsp" />
<title>课程设计管理系统</title>
<style type="text/css">
.txe {
	margin: 0px;
	height: 67px;
	width: 385px;
	background: #ccc;
	border-radius: 4px;
}
</style>
</head>
<body>
	<!-- begin搜索 -->
	<div class="well well-sm" id="searchIntro">
		<form id="searchForm" class="form-inline">
			<div class="row">
				<div class="form-group  col-md-12">
					<div class="input-group">
						<span class="input-group-addon">名字</span>
						<input class="form-control" name="name">
					</div>
					
					<div class="input-group" style="margin-left: 20px;">
						<button type="button" class="btn btn-success" onclick="loadPaging(1)">搜索</button>
						<input type="reset" id="formRest" style="display: none;">
						<button type="button" class="btn btn-success" onclick="resetIntro(1)" style="margin-left: 5px;">重置</button>
					</div>
				</div>
			</div>
		</form>
	</div>
	<div class="row">
		<div class="col-md-12" id="userList">
			<div class="panel panel-default">
				<div class="panel-heading" style="padding: 5px 15px;">
				</div>
				<div class="panel-body hfit" style="overflow-x: auto;">
					<input type="hidden" id="currentUserId">
					<!-- Table -->
				  	<table class="table table-bordered table-hover"  id="table_users_fqj">
					   <thead>
					      <tr>
					      	 <th style="width: 30px;"><input type="checkbox"></th>
					         <th field="ft" render="ft">类型</th>
					         <th field="fromName" render="name" >接收者/发送者</th>
					         <th field="content">内容</th>
					         <th field="creatTime">创建日期</th>
					         <th field="cz" render="btndos">操作</th>
					      </tr>
					   </thead>
					</table>
					<div id="table_Paging_fqj"></div>
				</div>
			</div>
		</div>
	</div>
	 <div id="addArea" class="panel panel-default" style="padding: 10px 30px;border: none;display: none;">
	 		<div class="list-group" id="messgae">
			</div>
			<form id="updataForm" class="form-horizontal" style="margin-top: 40px;">
				<div class="form-group col-md-14">
					<input type="hidden" id="id">
					<input type="hidden" id="toid">
				  	<textarea  class="form-control" placeholder="内容" id="content" ></textarea>
				</div>
				<div class="form-group col-md-14">
				  	<button type="button" class="btn btn-default form-control repy" >回复</button>
				</div>
			</form>
		</div>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/system/bootstrapTable.js?v=<%=getServletContext().getAttribute("version") %>"></script>
	<script type="text/javascript">
		/* 初始化 start */
		$(function() {
			var divheight = $(window).height();//初始化修改div的高度
			divheight = divheight - 125;
			$(".hfit").css({
				height : divheight
			});
			loadPaging(1);
		});
		 
		function loadUsers(pageNum){
			var url=rootpath+"/mess/getlist.shtml";
			var offSet=(pageNum-1)*10;
			var searchData=$("#searchForm").getFormData();
			searchData.offSet=offSet;
			searchData.pageSize=10;
			$.post(url,searchData,function(rows){
				$("#table_users_fqj").table(rows);
				//初始化分页插件
			});
		}
		function loadPaging(pageNum){
			var url=rootpath+"/mess/getlist.shtml";
			var offSet=(pageNum-1)*10;
			var searchData=$("#searchForm").getFormData();
			searchData.offSet=offSet;
			searchData.pageSize=10;
			$.post(url,searchData,function(data){
				var rows=data.items;
				var count=data.rowsCount;
				$("#table_users_fqj").table(rows);
				//初始化分页插件
				$("#table_Paging_fqj").tablePaging(1,10,count,"loadUsers");
			});
		}
		/*重置*/
		function resetIntro(){
			$("#searchForm").reset();
			loadPaging(1);
		}
		 
		function ft(e){
			var row=e.row;
			if(row.ft==0){
				return "发送";
			}else{
				return "接收";
			}
		}
		function name(e){
			var row=e.row;
			if(row.ft==0){
				return row.toName;
			}else{
				return row.fromName;
			}
		}
		
		function btndos(e){
			var row=e.row;
			var btn='<button type="button" class="btn btn-default btn-sm" onclick="show('+row.id+','+row.fromId+','+row.toId+','+row.ft+')">查看</button>';
			if(row.isRead==1){
				btn+="<span>有新回复啦</span>"
			}
			return btn;
		}
		
		function show(id,fromId,toId,ft){
			$('#messgae').html('')
			$("#id").val(id);
			if(ft==1){
				$("#toid").val(fromId);
			}else{
				$("#toid").val(toId);
			}
			$("#content").val('');
			var url = rootpath + "/mess/setIsRead.shtml";
			$.post(url,{'id':id,'isRead':0},function(data) {
				if(data.status){
					data = jQuery.parseJSON(data.data);
					var htm='';
					$.each(data,function(i,obj){
						htm=htm+'<p class="list-group-item" >'+obj.fromName+'：<textarea class="txe" readonly="readonly" >'+obj.content+'</textarea></p>'
					});
					$('#messgae').html(htm);
				}
			});
			
			layer.open({
				 type : 1,
				title : '消息',
				 area : [ '580px', '500px' ],
			  content : $('#addArea'),
			  end:function(){
				  loadPaging(1);
			  }
			});
		}
		
		$('.repy').click(function(){
			var id=$("#id").val();
			var toid= $("#toid").val();
			var content=$("#content").val();
			var mes=new Object();
			mes.mid=id;
			mes.toId=toid;
			mes.content=content;
			var url = rootpath + "/mess/saverep.shtml";
			$.post(url,mes,function(data) {
				if(data.status){
					$('#messgae').html('');
					$("#id").val('');
					$("#toid").val('');
					$("#content").val('');
					layer.closeAll();
				}
			});
		})
		 
	</script>
	
</body>
</html>
